<?php

namespace App\Http\Controllers\App;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\System;
use App\Models\SystemLog;

class SytemController extends Controller
{
	/**
	 * 展示分配比例
	 * @return [type] [description]
	 */
	public function show()
	{	
		$info = System::find(1);

		return self::json($info);
	}

	/**
	 * 修改分配比例
	 * @param  Request $requset [description]
	 * @return [type]           [description]
	 */
	public function edit( Request $requset )
	{
		$ping_fee   = (int)$requset->input('ping_fee');
		$shop_fee   = (int)$requset->input('shop_fee');
		$queque_fee = (int)$requset->input('queque_fee');
		$fanli_fee  = (int)$requset->input('fanli_fee');

		if ( ($ping_fee + $shop_fee + $queque_fee + $fanli_fee) !== 100) {

			return self::error('请传递正确的参数');
		}
		$admin_id   = session('admin_id', 0);

		$info      = System::find(1);

		$info->ping_fee   = $ping_fee;
		$info->shop_fee   = $shop_fee;
		$info->queque_fee = $queque_fee;
		$info->fanli_fee  = $fanli_fee;
		$info->admin_id   = $admin_id;
		$info->save();
	
		return self::success('修改成功');
	}

	/**
	 * 系统金额日志
	 * @return [type] [description]
	 */
	public function moneyLog( Request $requset )
	{
		$num = $requset->input('num')?$requset->input('num'):20;

		$data = SystemLog::paginate($num);
		
		return self::json($data);		
	}

	/**
	 * 每页多少条
	 * @return [type] [description]
	 */
	public function pageMum()
	{
		$arr = [ 10, 20, 50, 100, 200, 500, 1000];

		return self::json($arr);
	}
}
